package com.exchange.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exchange.entity.pojo.*;
import com.exchange.entity.vo.DetailPowerRecord;
import com.exchange.entity.vo.DetailPowerStatusVo;
import com.exchange.entity.vo.ManagerPowerVo;
import com.exchange.service.*;
import com.exchange.until.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @Author 董慧珍
 * @Date 2024/04/28
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/manager")
@Tag(name = "管理员")
public class ManageController {
    @Autowired
    private DetailPowerService detailPowerService;
    @Autowired
    private ReservationRecordService reservationRecordService;
    @Autowired
    private PowerService powerService;
    @Autowired
    private PowerStatusService powerStatusService;
    @Autowired
    private MapService mapService;
    @Autowired
    private UserService userService;

    /**
     * 电池列表
     * 查询某个地点某个电站的某个电柜的电池
     * */

    @GetMapping("/list")
    @Operation(operationId = "电池列表（可以查询某个地点某个电站的某个电柜的电池）")
    public Result list(@RequestParam(name = "offset")Integer offset,
                       @RequestParam(name = "pageSize")Integer pageSize,
                       @RequestParam(name = "mid",defaultValue = "")Integer mid,
                       @RequestParam(name = "id",defaultValue = "")Integer id,
                       @RequestParam(name = "pid",defaultValue = "")Integer pid,
                       @RequestParam(name = "status",required = false)Integer status){
        System.err.println(pid);
        System.err.println(status);
        Page<DetailPowerStatusVo> list = detailPowerService.findAll(offset,pageSize,mid,id,pid,status);
        return Result.success(list);
    }
    /**
     * 电柜列表
     * 查询某个地点某个电站的某个电柜
     * */
    @GetMapping("/managerPowerList")
    @Operation(operationId = "电柜列表（可以查询某个地点某个电站的某个电柜）")
    public Result managerPowerList(@RequestParam(name = "offset")Integer offset,
                       @RequestParam(name = "pageSize")Integer pageSize,
                       @RequestParam(name = "mid",defaultValue = "")Integer mid,
                       @RequestParam(name = "id",defaultValue = "")Integer id,
                       @RequestParam(name = "pid",defaultValue = "")Integer pid,
                       @RequestParam(name = "status",required = false)Integer status){
        System.err.println("mid-------"+mid);
        System.err.println("pid-------"+pid);
        System.err.println("status-------"+status);
        Page<ManagerPowerVo> list = this.powerStatusService.managerPowerList(offset,pageSize,mid,id,pid,status);
        return Result.success(list);
    }
    /**
     * 添加电柜信息
     * 添加电柜信息
     * */
    @PostMapping("/addManagerPower")
    @Operation(operationId = "添加电柜信息")
    public Result addManagerPower(@RequestBody PowerStatus powerStatus){
        System.err.println("powerStatus--------"+powerStatus);
        boolean b = this.powerStatusService.addManagerPower(powerStatus);
        return Result.success(b);
    }
    /**
     * 电池记录
     * 查询单个电池的预约记录
     * */
    @PostMapping("/battery/{id}")
    @Operation(operationId = "电池记录")
    public Result battery(@PathVariable(name = "id") Integer id) {
        List<DetailPowerRecord> detailPowerStatusVo = this.reservationRecordService.findById(id);
        return Result.success(detailPowerStatusVo);
    }
    /**
     * 用户列表
     * */
    @GetMapping("/personalList")
    @Operation(summary = "个人中心列表")
    public Result personalList(@RequestHeader String token) {
        User user = this.userService.selectPersonal(token);
        return Result.success(user);
    }
    /**
     * 所有位置
     * */
    @GetMapping("/midList")
    @Operation(summary = "所有位置")
    public Result midList() {
        List<Map> list = this.mapService.list();
        return Result.success(list);
    }
    /**
     * 所有电站
     * */
    @GetMapping("/powerList")
    @Operation(summary = "所有电站")
    public Result powerList(@RequestParam(name = "mid",defaultValue = "") Integer mid) {
        List<Power> power=this.powerService.powerList(mid);
        return Result.success(power);
    }
    /**
     * 所有电柜
     * */
    @GetMapping("/powerStatesList")
    @Operation(summary = "所有电柜")
    public Result powerStatesList(@RequestParam(name = "id",defaultValue = "") Integer id) {
        List<PowerStatus> PowerStatus=this.powerStatusService.powerStatesList(id);
        return Result.success(PowerStatus);
    }
    /**
     * 根据id查找电池
     * */
    @PostMapping("/findId")
    @Operation(summary = "根据id查找电池")
    public Result findId(@RequestParam(name = "id",defaultValue = "") Integer id){
        DetailPower id1 = this.detailPowerService.findId(id);
        return Result.success(id1);
    }
    /**
     * 根据id查找电柜
     * */
    @PostMapping("/managerPowerFindId")
    @Operation(summary = "根据id查找电柜")
    public Result managerPowerFindId(@RequestParam(name = "id",defaultValue = "") Integer id){
        ManagerPowerVo id1 = this.powerStatusService.managerPowerFindId(id);
        return Result.success(id1);
    }
    /**
     * 修改电柜状态
     * */
    @PostMapping("/updatePowerState")
    @Operation(summary = "修改电柜状态")
    public Result updatePowerState(@RequestBody PowerStatus powerStatus){
        boolean b = this.powerStatusService.updateById(powerStatus);
        return Result.success(b);
    }
    /**
     * 修改电池状态
     * */
    @PostMapping("/updateState")
    @Operation(summary = "修改电池状态")
    public Result updateState(@RequestBody DetailPower detailPower){
        boolean b = this.detailPowerService.updateById(detailPower);
        return Result.success(b);
    }
}
